<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>${appname}</title>
<%@ include file="/WEB-INF/view/common/css_js_ace.jsp"%>
<%-- <link rel="stylesheet" href="${ctx}/static/css/dataTables/jquery.dataTables.min.css" /> --%>
<%-- <link rel="stylesheet" href="${ctx}/static/css/dataTables/dataTableStyle.css" /> --%>
<%-- Start of dataTables--%>
<link rel="stylesheet" href="${ctx}/static/css/dataTables/dataTables.fontAwesome.css" />
<link rel="stylesheet" href="${ctx}/static/css/dataTables/dataTables.bootstrap.css" />
<script src="${ctx}/static/js/lib/dataTables/jquery.dataTables.min.js"></script>
<script src="${ctx}/static/js/lib/dataTables/dataTables.bootstrap.js"></script>
<%-- End of dataTables--%>
<script type="text/javascript">
$(document).ready(function() {
	  $('table.display').dataTable({
		    language: {
		        "sProcessing": "处理中...",
		        "sLengthMenu": "显示 _MENU_ 项结果",
		        "sZeroRecords": "没有匹配结果",
		        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
		        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
		        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
		        "sInfoPostFix": "",
		        "sSearch": "搜索:",
		        "sUrl": "",
		        "sEmptyTable": "暂无角色信息",
		        "sLoadingRecords": "载入中...",
		        "sInfoThousands": ",",
		        "oPaginate": {
		            "sFirst": "首页",
		            "sPrevious": "上页",
		            "sNext": "下页",
		            "sLast": "末页"
		        },
		        "oAria": {
		            "sSortAscending": ": 以升序排列此列",
		            "sSortDescending": ": 以降序排列此列"
		        }
		    },
		    "pagingType": "full_numbers",
		    "lengthMenu": [ [ 5, 10, 25, 50, 75, 100, -1 ], [ 5, 10, 25, 50, 75, 100, "所有" ] ],
		    "displayLength": 5,
		    "order": [[ 6, "desc" ]],
		    "columnDefs": [ {
		        "targets": 'nosort',
		        "orderable": false
		      } ]
		});
	  $('table.display')
		.removeClass( 'display' )
		.addClass('table table-striped table-bordered');
	  $('#selectIds').addClass('center');
	} );
/**
 * 删除用户角色信息
 */
function userRoleDel(roleId){
	window.parent.ui.confirm('确认删除该用户角色信息？',function(){
		var userCode = document.getElementById("curUserCode").innerText || document.getElementById("curUserCode").textContent;
	    $.ajax({
	           type: "POST",
	           dataType:"json",
	           cache: false,
	           url: _ctx + "/pub/sysmgr/usermgr/user_role_role_del.do",
	           data: {roleId:roleId,userName:userCode},
	           beforeSend : function(){
	           },
	           success: function(resp){
	        	   if(resp.status == '1'){
	        		   window.parent.ui.msg(resp.msg, 1);
					   ui.go(location.href);
				   }else{
					   window.parent.ui.msg(resp.msg, 0);
				   }
	           },
	           error:function(){
	        	   window.parent.ui.msg( '请求发送失败！',0 );
	           }
	    });
	});
}

/**
 * 批量删除用户角色信息
 */
function userRoleDelBatch(){
	var userCode = document.getElementById("curUserCode").innerText || document.getElementById("curUserCode").textContent;
    var curChecked = document.getElementsByName("roleChecked");
    var curroleChecked = "";
    for(var i=0;i<curChecked.length;i++){
        var temp=document.getElementsByName("roleChecked")[i];
        if(temp.checked){
        	curroleChecked = curroleChecked + temp.value + ",";
        }
    }
    if(curroleChecked.length == 0){
		ui.msg('请至少选择一条要删除的记录!');
		return;
	}
    window.parent.ui.confirm('确认删除选中的用户角色信息？',function(){
	    $.ajax({
	           type: "POST",
	           dataType:"json",
	           cache: false,
	           url: _ctx + "/pub/sysmgr/usermgr/user_role_role_del_batch.do",
	           data: {roleIds:curroleChecked,userName:userCode},
	           beforeSend : function(){
	           },
	           success: function(resp){
	        	   if(resp.status == '1'){
	        		   window.parent.ui.msg(resp.msg, 1);
					   ui.go(location.href);
				   }else{
					   window.parent.ui.msg(resp.msg, 0);
				   }
	           },
	           error:function(){
	        	   window.parent.ui.msg( '请求发送失败！',0 );
	           }
	    });
    });
}

function userRoleAdd(){
	var userCode = document.getElementById("curUserCode").innerText || document.getElementById("curUserCode").textContent;
	//$('#userRoleAddModal').modal('show');
	$.ajax({
		   type: "GET",
		   dataType:"html",
		   cache: false,
		   url: _ctx + "/pub/sysmgr/usermgr/user_role_role_add.do",
		   data: {id:userCode},
		   beforeSend : function(){
	       },
		   success: function(content){
			   $('#userRoleAddDiv').html( content );
			   var hiddenByClick = false;
			   window.parent.iframeModal("toIframeModal", $('#userRoleAddModal').html(), hiddenByClick);
		   },
		   error: function(){
			   $('#userRoleAddModal').modal('hide');
			   ui.msg( '请求发送失败！',0 );
		   }
	});
}
</script>
<style type="text/css">
#selectIds{
   text-align: center;   
}
</style>
</head>
<body>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <div class="main-content" style="margin-left: 0px;">
			<div class="breadcrumbs" id="breadcrumbs">
				<ul class="breadcrumb" style="margin-left: 4px;">
                    <li>
                        <i class="icon-home home-icon"></i>
						首页
                    </li>
                    <li>
						系统管理
                    </li>
                    <li>
						用户角色管理
                    </li>
                    <li class="active">用户角色管理</li>
                </ul>
            </div>

            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        
                        <div class="widget-box">
                            <div class="widget-header widget-header-flat">
                                <h5 class="smaller lighter">
                                    <i class="icon-list"></i> &nbsp;用户信息
                                </h5>
                                <div class="widget-toolbar no-border">
                                	<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="userRoleAdd()"><i class="icon-plus-sign"></i>添加角色&nbsp;</a>
                                    <a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="userRoleDelBatch()"><i class="icon-lock icon-on-right"></i> 批量删除角色&nbsp;</a>
                                    <a href="#" data-action="collapse">
                                        <i class="icon-chevron-up"></i>
                                    </a>
                                </div>
                            </div>

                            <div class="widget-body">
                                <div class="widget-main row">
                                	<div class="profile-user-info profile-user-info-striped row">
										<div class="profile-info-row col-xs-6">
											<div class="profile-info-name">用户ID</div>
											<div class="profile-info-value">
												<span class="editable" id="curUserCode">${vo.id}</span>
											</div>
										</div>
										<div class="profile-info-row col-xs-6">
											<div class="profile-info-name">用户姓名</div>
											<div class="profile-info-value">
												<span class="editable">${vo.userName}&nbsp;</span>
											</div>
										</div>
                                    	<div class="profile-info-row col-xs-6">
											<div class="profile-info-name">联系电话</div>
											<div class="profile-info-value">
												<span class="editable">${vo.tel}&nbsp;</span>
											</div>
										</div>
										<div class="profile-info-row col-xs-6">
											<div class="profile-info-name">邮箱地址</div>
											<div class="profile-info-value">
												<span class="editable">${vo.email}&nbsp;</span>
											</div>
										</div>
									</div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="hr hr12 hr-dotted"></div>
                        
                        <h5 class="header blue lighter smaller">
                            <i class="ace-icon fa fa-bars smaller-90"></i>
							&nbsp;已关联角色列表
                        </h5>

                        <div id="optDiv">
                            <div class="table-responsive">
                                <table name="example" class="display" cellspacing="0" width="100%" >
									<thead>
										<tr>
											<th id="selectIds" class="center nosort" style="padding-right: 8px;">
												<label>
												<input type="checkbox" class="ace" onclick="$.checkBoxTriggerAll(this,'roleChecked')"/>
												<span class="lbl"></span>
												</label>
											</th>
											<th style="word-break: keep-all;white-space:nowrap;">角色编码</th>
											<th style="word-break: keep-all;white-space:nowrap;">角色名称</th>
											<th style="word-break: keep-all;white-space:nowrap;">角色类型</th>
											<th style="word-break: keep-all;white-space:nowrap;">所属机构</th>
											<th style="word-break: keep-all;white-space:nowrap;">状态</th>
											<th style="word-break: keep-all;white-space:nowrap;">公共角色</th>
											<th style="word-break: keep-all;white-space:nowrap;">创建时间</th>
											<th style="word-break: keep-all;white-space:nowrap;">描述</th>
											<th class="nosort" style="word-break: keep-all;white-space:nowrap;color: #707070; ">操作</th>
										</tr>
									</thead>
	
									<tbody>
										<c:forEach var="vo" items="${roleInfoList}">
										<tr>
											<td class="center">
												<label>
												<input name="roleChecked" type="checkbox" class="ace" value="${vo.id}"/>
												<span class="lbl"></span>
												</label>
											</td>
											<td>${vo.roleCode}&nbsp;</td>
											<td>${vo.roleName}&nbsp;</td>
											<td>${cm:ctname('authusertype',vo.roleType)}&nbsp;</td>
											<td>${vo.orgCode}&nbsp;</td>
											<td>${cm:ctname('entity_status',vo.roleStatus)}&nbsp;</td>
											<td>${cm:yesNoStr(vo.isDefault)}&nbsp;</td>
											<td><fmt:formatDate value="${vo.modified}" pattern="yyyy-MM-dd HH:mm:ss" />&nbsp;</td>
											<td>${vo.remark}&nbsp;</td>
											<td style="word-break: keep-all;white-space:nowrap;" align="center">
												<div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                                    <a class="red" href="javascript:void(0);" onclick="userRoleDel('${vo.id}')" title="删除">
                                                        <i class="icon-trash bigger-130"></i>
                                                    </a>
                                                </div>
											</td>
										</tr>
										</c:forEach>
									</tbody>
								</table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="userRoleAddModal" class="modal fade" role="dialog" tabindex="-1" aria-labelledby="增加" aria-hidden="false">
	<div class="modal-dialog modal-lg" style="width: 1100px;">
		<div class="modal-content">
			<div class='widget-header widget-header-small'><h5 class='smaller'> 增加用户角色信息</h5></div>
			<div id="userRoleAddDiv">
				<p class="text-center" style="font-size: 25px; color: #428bca;">
					<span class="icon icon-cog icon-spin"></span>
				</p>
				<p class="text-center" style="font-size: 12px; color: #428bca; margin-top: -10px; margin-bottom: 0px;">
					<span>可配置角色列表加载中...</span>
				</p>
			</div>
		</div>
	</div>
</div>

</body>
</html>
